package com.xxx.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xxx.anno.AnnoAutowired;
import com.xxx.anno.AnnoController;
import com.xxx.anno.AnnoRequestMapping;
import com.xxx.anno.AnnoRequestParam;
import com.xxx.service.DemoService;

/**
 * 使用自定义注解，手写springmvc：Controller类
 */
@AnnoController // 自定义@Controller注解
@AnnoRequestMapping("/demo") // 自定义@RequestMapping注解
public class DemoController {
	
	@AnnoAutowired("DemoServiceImpl")
	private DemoService demoService;
	
	// http://127.0.0.1:8080/mvc/demo/test?name=guweqiang&age=21
	@AnnoRequestMapping("/test")
	public void test(HttpServletRequest request, HttpServletResponse response,
			@AnnoRequestParam("name") String name, @AnnoRequestParam("age") String age) {
		try {
			PrintWriter pw = response.getWriter();
			String result = demoService.query(name, age);
			pw.write(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
